<template>
  <div>
    <!-- 数据据统计区域 -->
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="box-card">
          <div class="card_title">
            <span>用户总数</span>
            <span><i class="el-icon-user-solid"> </i></span>
          </div>
          <div class="card_count">网盘总用户：{{ userCount }} 名</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="box-card">
          <div class="card_title">
            <span>总数</span>
            <span><i class="el-icon-coin"> </i></span>
          </div>
          <div class="card_count">网盘总数：{{ fileCount.total }} 个</div>
        </el-card></el-col
      >
      <el-col :span="6">
        <el-card class="box-card">
          <div class="card_title">
            <span>文件夹数</span>
            <span><i class="el-icon-folder-opened"></i> </span>
          </div>
          <div class="card_count">文件夹总数：{{ fileCount.dircounts }} 个</div>
        </el-card></el-col
      >
      <el-col :span="6">
        <el-card class="box-card">
          <div class="card_title">
            <span>文件数</span>
            <span><i class="el-icon-document"> </i></span>
          </div>
          <div class="card_count">文件总数：{{ fileCount.filecounts }} 个</div>
        </el-card></el-col
      >
    </el-row>

    <el-row class="row_counts" :gutter="10">
      <el-col :span="24">
        <!-- 卡片5 -->
        <el-card class="echart_card">
          <div class="charts_line" ref="charts"></div>
        </el-card>
      </el-col>
    </el-row>

    <el-row class="row_counts" :gutter="10">
      <el-col :span="24">
        <!-- 卡片6 -->
        <el-card class="echart_card">
          <div class="charts_line" ref="chartss"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userCount: "",
      fileCount: {
        total: "1",
        dircounts: "1",
        filecounts: "1",
      },
      xdata: [],
      ydata: [],
      zdata: [],
    };
  },
  created() {
    this.getUserCount();
    this.getFileCount();
    this.getFileCountByDay();
  },
  methods: {
    async getUserCount() {
      const { data: res } = await this.$http.get("getUserCount");
      console.log(res);
      // 给userCount赋值操作
      this.userCount = res.data.usercount;
    },
    async getFileCount() {
      const { data: res } = await this.$http.get("getFileCount");
      console.log(res);
      // 给fileCount的赋值操作
      this.fileCount.total = res.data.total;
      this.fileCount.dircounts = res.data.dircounts;
      this.fileCount.filecounts = res.data.filecounts;
    },
    async getFileCountByDay() {
      const { data: res } = await this.$http.get("getFileCountByDay");
      console.log(res);
      this.xdata = res.data.name;
      console.log(this.xdata);
      this.ydata = res.data.value;
      console.log(this.ydata);
      const myChart = this.$echarts.init(this.$refs.charts);
      const myChartt = this.$echarts.init(this.$refs.chartss);
      // const myChart2 = this.$echarts.init(this.$refs.charts2);

      let option;
      let option1;
      let option2;
      option = {
        title: {
          text: "每日新增文件数",
          textStyle: {
            //设置主标题的文字风格
            color: "black", //字体颜色
            fontSize: 25,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          data: ["新增文件数", "新增删除数", "新增收藏数"],
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: this.xdata,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "新增文件数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.ydata,
          },
          {
            name: "新增删除数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: [4, 3, 16, 6, 5, 11, 9],
          },

          {
            name: "新增收藏数",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: [2, 9, 5, 10, 12, 10, 4],
          },
        ],
      };
      var scaleData = [
        {
          name: "成品图片",
          value: 56,
        },
        {
          name: "走秀视频",
          value: 48,
        },
        {
          name: "背景音乐",
          value: 8,
        },
        {
          name: "服装资料",
          value: 37,
        },
      ];
      // 随机颜色
      var rich = {
        white: {
          color: "#ddd",
          align: "center",
          padding: [3, 0],
        },
      };
      var placeHolderStyle = {
        normal: {
          label: {
            show: false,
          },
          labelLine: {
            show: false,
          },
          color: "rgba(0, 0, 0, 0)",
          borderColor: "rgba(0, 0, 0, 0)",
          borderWidth: 0,
        },
      };
      function bg2() {
        return "#" + Math.floor(Math.random() * 0xffffff).toString(16);
      }

      function rancolors(len) {
        var color = [];
        for (var i = 0; i <= len; i++) {
          var sjys = bg2();
          color.push(sjys);
          for (var i = 0; i < color.length; i++) {
            if ((color[i] = sjys)) {
              color[i] = bg2();
            }
          }
        }
        return color;
      }
      var data = [];
      var color = rancolors(7);
      for (var i = 0; i < scaleData.length; i++) {
        data.push(
          {
            value: scaleData[i].value,
            name: scaleData[i].name,
            itemStyle: {
              normal: {
                borderWidth: 50,
                shadowBlur: 100,
                borderColor: color[i],
                shadowColor: color[i],
              },
            },
          },
          {
            value: 50,
            name: "",
            itemStyle: placeHolderStyle,
          }
        );
      }
      var seriesObj = [
        {
          name: "",
          type: "pie",
          clockWise: false,
          radius: [60, 150],
          hoverAnimation: false,
          itemStyle: {
            normal: {
              label: {
                show: true,
                position: "outside",
                color: "#ddd",
                fontSize: "22px",
                formatter: function (params) {
                  var percent = 0;
                  var total = 0;
                  for (var i = 0; i < scaleData.length; i++) {
                    total += scaleData[i].value;
                  }
                  percent = ((params.value / total) * 100).toFixed(0);
                  if (params.name !== "") {
                    return params.name + "\n{white|" + "占比" + percent + "%}";
                  } else {
                    return "";
                  }
                },
                rich: rich,
              },
              labelLine: {
                length: 30,
                length2: 100,
                show: true,
                color: "#00ffff",
              },
            },
          },
          data: data,
        },
      ];
      option1 = {
        title: {
          text: "文件类型占比",
          x: "20", //设置标题位置
          y: "30",
          textStyle: {
            //设置主标题的文字风格
            color: "red", //字体颜色
            fontSize: 25,
          },
        },
        backgroundColor: "#04243E",

        tooltip: {
          show: false,
        },
        legend: {
          show: false,
        },
        toolbox: {
          show: false,
        },
        series: seriesObj,
      };

      myChart.setOption(option);
      myChartt.setOption(option1);
      // myChart2.setOption(option2);
    },
  },
};
</script>

<style lang="less" scoped>
.card_title {
  display: flex;
  justify-content: space-between;
  color: rgb(66, 67, 71);
  font-size: 16px;
}
.card_count {
  font-size: 20px;
}
.charts_line {
  width: 1100px;
  height: 460px;
}
</style>
